import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:intl/intl.dart';
import 'package:kxy_flutter_app/model/news_detail.dart';

class ContentNewsWidget extends StatelessWidget {
  final NewsDetail newsDetail;
  final format = new DateFormat('yyyy年MM月dd日');
  ContentNewsWidget({this.newsDetail});

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 15, vertical: 20),
        child: ListBody(
          children: [
            _createNewsTitle(),
            _createNewsDate(),
            _createNewsContent(),
          ],
        ),
      ),
    );
  }

  Widget _createNewsTitle() {
    return Text(
      newsDetail.title,
      style: TextStyle(
        fontSize: 18,
        fontWeight: FontWeight.bold,
        color: Colors.black,
      ),
    );
  }

  Widget _createNewsDate() {
    var date = format.format(newsDetail.createTime);
    return Padding(
      padding: EdgeInsets.only(top: 10),
      child: Text(
        '${newsDetail.hits}次阅读 | $date发布',
        style: TextStyle(
          color: Colors.black54,
          fontSize: 12,
        ),
      ),
    );
  }

  Widget _createNewsContent() {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 10),
      child: HtmlWidget(
        newsDetail.content,
        textStyle: TextStyle(
          fontSize: 16,
          color: Colors.black,
          height: 1.6,
          letterSpacing: 0.2,
        ),
      ),
    );
  }
}
